extends Node2D

var initial_weapons  =[]
@export var active_weapons : Array[BaseWeapon]


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	initial_weapons.append(preload("res://Scene/Weapon/fireball.tscn"))
	
	for weapon in initial_weapons:
		var weapon_instance = weapon.instantiate()
		add_weapon(weapon_instance)

func apply_upgrade(upgrade_id: String):
	
	var weapon_name= get_weapon_name_from_upgrade_id(upgrade_id)
	print(weapon_name)
	for weapon in active_weapons:
		if weapon.weapon_name==weapon_name:
			print("cg")
			weapon.apply_upgrade(upgrade_id)
		

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	for weapon in active_weapons:
		weapon.update(delta)

func add_weapon(weapon):
	add_child(weapon)
	active_weapons.append(weapon)

func get_weapon_name_from_upgrade_id(upgrade_id: String) -> String:
	# 从升级ID中提取武器名称（按下划线分割，取第一部分）
	var parts = upgrade_id.split("_")
	if parts.size() > 0:
		return parts[0]
	return ""
